Getting Started With Notebooks and the V-REP Simulator

The Coppelia Robotics V-REP simulator is a fully featured three dimensional simulator for a wide range of robot models.

As well as providing an integrated development environment that supports scripting of robot programs, the simulator offers an API A(aapplication programming interface) that allows the simulated robots to be controlled from a remote script, such as a script executed via a Jupyter notebook.

The robots that appear in the simulator all have real world counterparts. In this course, you will have an opportunity to work with several simulated robots, including:

  • a Pioneer3DX research robot;
  • a simple *LineTracer& robot;
  • a Lego EV3 robot.

Working With the Simulator

To start programming the robots, you need to ensure that two applications are running on your computer:

  • Jupyter notebooks
  • the V-REP simulator

To simplify things, we have created some IPython magic (really! That's what it's called...) that allows you to connect to the V-REP simulator from a notebook code cell. A robot inside a simulator scene can then be controlled directly from Python code run in the code cell.

To connect to the simulator, first ensure that the simulator application is running.

In the notebook, load in and run the generic initialisation scripts in a code cell:

%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'

Load in an run an appropriate robot class definition file:

%run 'vrep_models/ROBOT_MODEL.ipynb'

The following have been defined:

Robot Class Robot definition file
lineTracer vrep_models/lineTracer.ipynb
PioneerP3DX vrep_models/PioneerP3DX.ipynb

You can then open a scene in the simulator and connect to it using cell magic of the form:

%%vrepsim 'PATH/TO/SCENE.ttt' RobotClass

The magic cell magic then works as follows:

  • connect to the simulator
  • load the specified scene; the scene should include a simulated robot of a kind that matches the specified robot class
  • create a python object called robot that instantiates a class corresponding to RobotClass; an object corresponding to that robot class should exist inside the scene
  • run the code in the cell

The following scenes and robot classes have been defined:

Notebook Scene Robot Class
Demo - linetracer.ipynb OU_grey lines.ttt lineTracer
Demo - square 1.ipynb OU_Pioneer.ttt PioneerP3DX

For example, the following cell loads in the initialisation scripts:


In [1]:
%run 'Set-up.ipynb'
%run 'Loading scenes.ipynb'

Load in a robot definition file appropriate to the scene you intend to load - when it loads it will give you a preview of the robot classes that have been loaded in and the methods defined on them.


In [2]:
%run 'vrep_models/PioneerP3DX.ipynb'


Loading class: PioneerP3DX_base
This is a base class for the PioneerP3DX_base model

Loading class: PioneerP3DX
Methods available in PioneerP3DX:
	get_orientation
	get_orientation_degrees
	getvalleft
	getvalright
	move_backward
	move_forward
	rotate_left
	rotate_right
	set_two_motor
	ultrasonic_left_length
	ultrasonic_right_length

Loading class: PioneerP3DXL
Methods available in PioneerP3DXL:
	color_left
	color_right
	get_orientation
	move_backward
	move_forward
	rotate_left
	rotate_right
	set_two_motor
	ultrasonic_left_length
	ultrasonic_right_length

The following text widgets are available for display: sensorText1, sensorText2

The following cell connects to the simulator, loads the OU_Pioneer.ttt scene, and connects to the PioneerP3DX object that is preloaded inside the scene. The robot object is created automatically and can be called by the code running in the cell.

Run the cell and watch what happens to robot in the simulator.


In [5]:
%%vrepsim '../scenes/OU_Pioneer.ttt' PioneerP3DX
import time
robot.rotate_right()
time.sleep(5)

You can also run the magic without specifying a scene name. In this case, the code in the cell will run against the currently loaded, in focus scene. TO DO - CHECK THIS For example:

%%vrepsim PioneerP3DX

Note that you will need to ensure that a robot of the correct class is available inside the scene.

Valid models can be found in the ../models directory:


In [6]:
!ls ../models


LEGO_EV3_GROUP.ttm LEGO_EV3_MERGE.ttm README.md

Managing Your Screen

The simulator and the notebook can each take up quite a lot of your computer screen. We suggest a screen layout something like the following:

You can find a range of help files describing how to work with the actual simulator, such as changing camera views and moving the robot, in the ../howtos directory.


In [8]:
!ls ../howtos


Adding_Lines_to_a_Scene.md         Pen_Down_Robot_Trajectory_Trace.md
Adding_Odometry.md                 Working_With_VREP_Graph_Object.md
Environment_Camera_Views.md        Working_With_a_New_Model.md
Floor_resizing.md

Problems With The V-REP Simulator

Hopefully, you won't have any problems starting the simulator and connecting to it. If you do, here are some things to check.

Problems starting the simulator

Check environment variable settings - these can be set via the Set-up.ipynb notebook.

Problems connecting to the simulator

You may need to check the connection settings. You can set these from a notebook used to control a robot by setting the following variables:

  • vrep_ip: by default, this is set to '127.0.0.1'
  • vrep_port: by default, this is set to 19997